package me.frank.mail.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Frank Wang
 * @Description:
 * @date 2018/8/21 11:44
 */
@RestController
public class TestController {
    @Autowired
    private MailService mailService;

    @Autowired
    private  AsyncService asyncService;

    @GetMapping("mail/send")
    public ResponseEntity<String> sendEmail(@RequestParam(name = "to") String to,
                                            @RequestParam(name = "subject") String subject,
                                            @RequestParam(name = "count",defaultValue = "1") Integer count,
                                            @RequestParam(name = "content") String content){
        for (int i = 0; i < count; i++) {
            mailService.sendSimpleMail(subject,content+" copy "+i,to);
        }
        return ResponseEntity.ok("success!");
    }


    @GetMapping("test/async")
    public ResponseEntity<String> testAsync(@RequestParam(name = "subject") String subject,
                                            @RequestParam(name = "count",defaultValue = "1") Integer count){
        for (int i = 0; i < count; i++) {
            asyncService.printf(i);
        }
        return ResponseEntity.ok("success!");
    }
}
